package com.yy.job.core.config.xml;

import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;

import org.apache.commons.collections.CollectionUtils;

import com.google.common.collect.Maps;

/**
 * 任务
 * 
 * @author eleven.li
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
public class JobXmlConfig implements IXmlConfig{
	
	@XmlAttribute
	private String jobCode;

	@XmlAttribute
	private String jobName;

	/**
	 * 分钟
	 */
	@XmlElement
	private String lockTime;

	@XmlElementWrapper(name = "jobStepConfigs")
	@XmlElement(name = "jobStepConfig")
	private List<JobStepXmlConfig> jobStepConfigs;
	
	private Map<String,JobStepXmlConfig> jobStepMap;
	
	@Override
	public void build() {
		if(jobStepMap == null) {
			jobStepMap = Maps.newHashMap();
		}
		if(CollectionUtils.isEmpty(jobStepConfigs)) {
			return;
		}
		for(JobStepXmlConfig config : jobStepConfigs) {
			config.build();
			jobStepMap.put(config.getStepCode(), config);
		}
	}

	public String getJobCode() {
		return this.jobCode;
	}

	public void setJobCode(String jobCode) {
		this.jobCode = jobCode;
	}

	public String getJobName() {
		return this.jobName;
	}

	public void setJobName(String jobName) {
		this.jobName = jobName;
	}

	public String getLockTime() {
		return this.lockTime;
	}

	public void setLockTime(String lockTime) {
		this.lockTime = lockTime;
	}

	public List<JobStepXmlConfig> getJobStepConfigs() {
		return jobStepConfigs;
	}

	public void setJobStepConfigs(List<JobStepXmlConfig> jobStepConfigs) {
		this.jobStepConfigs = jobStepConfigs;
	}

	public JobStepXmlConfig findJobStepConfig(String stepCode) {
		return this.jobStepMap.get(stepCode);
	}

}
